<?php
/* @var $header string */
/* @var $model \frontend\modules\yii\models\FrameCatalogue */

use yii\bootstrap\Modal;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;

$form = ActiveForm::begin(["id" => "catalogue-form", "layout" => "horizontal", "enableAjaxValidation" => true]);

Modal::begin([
    'header' => '<h4>' . $header . '</h4>',
    'id' => 'create_dialog',
    'toggleButton' => ['label' => 'click me'],
    'footer' => Html::submitButton("Save", ["class" => "btn btn-primary"])
]);

echo $form->field($model, "cname")->label("Name")->textInput(["autofocus" => true]);
echo Html::hiddenInput('type', $header);
if($header == "Update"){
    echo $form->field($model, "id")->label(false)->hiddenInput();
}


Modal::end();

ActiveForm::end();


$js = <<<JS
$('#catalogue-form').on('ajaxComplete', function(event, jqXHR, textStatus){
   console.info(event, jqXHR, textStatus) ;
   if (textStatus == "parsererror") {
       $('#save-dialog').empty().append(jqXHR.responseText);
   }
});
JS;

$this->registerJs($js, \yii\web\View::POS_READY);